import { dataQueryAxios } from '@/utils/request.ts'
import { downloadBlobFile } from '@hs-admin/api'

export const exportList = (params: {
  keywords?: string
  type?: string
  status?: string
  view_all?: true
  release_item_id?: string
  page: number
  page_size: number
}): Promise<any> => {
  return dataQueryAxios({
    url: `/api/data-query/v1/exports`,
    method: 'get',
    params
  })
}

export const exportToLocal = (id: string) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/exports/${id}/file`,
    method: 'get',
    responseType: 'blob'
  }).then((res: any) => {
    downloadBlobFile(res, res.name)
  })
}

export const approveExport = (id: string) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/exports/${id}:approve`,
    method: 'post'
  })
}

export const rejectExport = (
  id: string,
  data: {
    message: string
  }
) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/exports/${id}:reject`,
    method: 'post',
    data
  })
}
